= simple_form_for([:admin, @plan]) do |f| 
	- if @plan.errors.any? 
		#error_explanation
			%h2= "#{pluralize(@plan.errors.count, "error")} prohibited this plan from being saved:"

			%ul
				-@plan.errors.full_messages.each do |msg| 
					%li= msg
	

	= f.input :name
	= f.input :price
	= f.input :billing_period, :collection => Plan::BILLING_PERIODS, :include_blank => false

	%fieldset
		%h4 Plan Attributes
		= f.label "Add new attribute"
		= text_field_tag "attribute_name"
		= link_to "Add attribute", "#", :id => "add_attribute"
		#optional_attributes
			-begin	
				- @plan.dynamic_attributes.each do |da|
					= f.label da[0].gsub("field_", "")
					= text_field_tag "plan[#{da[0]}]",	da[1]
					%br
			- rescue

	.actions
		= f.submit
		= link_to 'Cancel', :back
	
	:javascript
		$(document).ready(function(){
			$('#add_attribute').click(function(event) {
				event.preventDefault();
				if ($('#attribute_name').val() == '') {
					alert("You must give your attribute a name.");
				} else {
					$('#optional_attributes').append("<br><label>" + $('#attribute_name').val() +"</label><input name='plan[field_" + $('#attribute_name').val() +"]' id='field_" + $('#attribute_name').val() +"'>");
				}
			})
		})
		


